#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/9/25 21:32
# @Author  : Crissu
# @Site    : 
# @File    : cn2en.py
# @Software: PyCharm
'''
    文件夹名字重命名
    中文名变英文名
'''
import os, re
from pypinyin import pinyin, lazy_pinyin, Style

from configs import cn2en_config

def changeFloderName():
    rawPath = cn2en_config.FromPath
    newPath = cn2en_config.ToPath
    names = os.listdir(rawPath)
    for name in names:
        p = re.compile('[\u4e00-\u9fa5]')  # 这里是精髓，[\u4e00-\u9fa5]是匹配所有中文的正则，因为是unicode形式，所以也要转为ur
        nameList = p.split(name)
        numberLen = len(nameList[0])
        chName = name[numberLen:]
        pingyingName = "_".join(lazy_pinyin(chName))
        oldname = rawPath + name
        newname = newPath + nameList[0] + pingyingName
        print("oldname:", oldname)
        print("newname:", newname)
        os.rename(oldname, newname)
